package com.lh.recallbootrabbitmq.controller;

import com.lh.recallbootrabbitmq.bean.MqExchange;
import com.lh.recallbootrabbitmq.bean.MqQueue;
import com.lh.recallbootrabbitmq.constants.ExchangeTypeEnum;
import com.lh.recallbootrabbitmq.manage.BindManage;
import com.lh.recallbootrabbitmq.manage.ExchangeManage;
import com.lh.recallbootrabbitmq.manage.QueueManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lh
 * @Description:
 * @date 2021/8/24 17:14
 */
@RestController
public class TestController {
	@Autowired
	private ExchangeManage exchangeManage;
	@Autowired
	private QueueManage queueManage;
	@Autowired
	private BindManage bindManage;

	private static final String TEST_EXCHANGE_NAME = "com.lh.test.exchange";
	private static final String TEST_QUEUE_NAME = "com.lh.test.queue";

	@GetMapping
	@RequestMapping("declareExchange")
	public void declareExchange() {
		MqExchange mqExchange = new MqExchange();
		mqExchange.setName(TEST_EXCHANGE_NAME);
		mqExchange.setType(ExchangeTypeEnum.FANOUT);
		mqExchange.setAutoDelete(true);
		mqExchange.setDurable(true);
		exchangeManage.declareExchange(mqExchange);
	}

	@GetMapping
	@RequestMapping("declareQueue")
	public void declareQueue() {
		MqQueue mqQueue = new MqQueue();
		mqQueue.setName(TEST_QUEUE_NAME);
		mqQueue.setAutoDelete(true);
		mqQueue.setDurable(true);
		mqQueue.setExclusive(false);
		queueManage.declareQueue(mqQueue);
	}

	@GetMapping
	@RequestMapping("queueBind")
	public void queueBind() {
		bindManage.queueBind(TEST_QUEUE_NAME, TEST_EXCHANGE_NAME, TEST_QUEUE_NAME);
	}
}
